package com.sahyadri.web.bean;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Generic class used to return search results.  
 * 
 * @param <E> The Type of the expected result list
 */

public class SearchResults<E> {
	
	private long totalResultsFound;
	private List<E> resultList = new ArrayList<E>();
	private boolean maxResultsExceeded;
	
	public SearchResults(){
		
	}
	
	/**
	 * @param totalResultsFound
	 * @param resultList
	 */
	public SearchResults(long totalResultsFound, List<E> resultList) {
		this(totalResultsFound, resultList, false);
	}
	
	/**
	 * 
	 * @param totalResultsFound
	 * @param resultList
	 * @param maxResultsExceeded
	 */
	public SearchResults(long totalResultsFound, List<E> resultList, boolean maxResultsExceeded) {
		this.totalResultsFound = totalResultsFound;
		this.resultList = resultList;
		this.maxResultsExceeded = maxResultsExceeded;
	}

	public long getTotalResultsFound() {
		return totalResultsFound;
	}
	
	public void setTotalResultsFound(long totalResultsFound) {
		this.totalResultsFound = totalResultsFound;
	}
	
	public List<E> getResultList() {
		return resultList;
	}
	
	public void setResultList(List<E> resultList) {
		this.resultList = resultList;
	}

	public boolean isMaxResultsExceeded() {
		return maxResultsExceeded;
	}

	public void setMaxResultsExceeded(boolean maxResultsExceeded) {
		this.maxResultsExceeded = maxResultsExceeded;
	}

	/**
	 * Static factory method used to easily return an empty SearchResult
	 * 
	 */
	public static <T> SearchResults<T> emptySearchResult(){
		List<T> emptyList = Collections.emptyList();
		return new SearchResults<T>(0, emptyList);
	}
}